#include "StrategyPar.h"
#include "StarUtil.h"
using namespace std;
using namespace BWAPI;
StrategyPar::StrategyPar(void)
{

}


StrategyPar::~StrategyPar(void)
{
	
}

void StrategyPar::setTargetsSpecial()
{
	sort(targets.begin(), targets.end(), byDamageToHitPoints());
}


vector<string> & StrategyPar::getTargetPriority(string name)
{
	UnitType unit = UnitTypes::getUnitType(name);
	vector<string> backList;
	vector<string>::iterator prior = targetPriority.begin();
	targetPriority.erase(targetPriority.begin(), targetPriority.end());
	WeaponType gWeapon= unit.groundWeapon();
	WeaponType aWeapon= unit.airWeapon();
	int groundDamage =0, airDamage = 0;
	if(gWeapon != WeaponTypes::None)
	{
		groundDamage +=gWeapon.damageAmount()/gWeapon.damageCooldown();
		if(gWeapon.targetsAir())
			airDamage = gWeapon.damageAmount()/gWeapon.damageCooldown();
	}
	if(aWeapon != WeaponTypes::None)
	{	
		if(aWeapon.targetsGround())
			groundDamage +=aWeapon.damageAmount()/aWeapon.damageCooldown();
		airDamage = aWeapon.damageAmount()/aWeapon.damageCooldown();
	}	


	if(groundDamage >= airDamage)
	{
		for(vector<string>::iterator it=targets.begin();it!=targets.end();it++)
		{
			if(!(UnitTypes::getUnitType(*it).isFlyer()))
				targetPriority.push_back(*it);
			else
				backList.push_back(*it);
		}
	}
	else
	{
		for(vector<string>::iterator it=targets.begin();it!=targets.end();it++)
		{
			if((UnitTypes::getUnitType(*it).isFlyer()))
				targetPriority.push_back(*it);
			else
				backList.push_back(*it);
		}
	}
    for(vector<string>::iterator it=backList.begin();it!=backList.end();it++)
	{
		targetPriority.push_back(*it);
	}

	return targetPriority;
}